// es6 polyfill
import 'core-js/fn/array/find-index'

import Affix from './components/affix'
import Alert from './components/alert'
import BackTop from './components/back-top'
import Badge from './components/badge'
import Breadcrumb from './components/breadcrumb'
import Button from './components/button'
import Card from './components/card'
import Carousel from './components/carousel'
import Cascader from './components/cascader'
import Checkbox from './components/checkbox'
import Circles from './components/circle'
import Collapse from './components/collapse'
import ColorPicker from './components/color-picker';
import DatePicker from './components/date-picker'
import Dropdown from './components/dropdown'
import Form from './components/form'
import Icon from './components/icon'
import Input from './components/input'
import InputNumber from './components/input-number'
import LoadingBar from './components/loading-bar'
import Menu from './components/menu'
import Message from './components/message'
import Modal from './components/modal'
import Notice from './components/notice'
import Page from './components/page'
import Poptip from './components/poptip'
import Progress from './components/progress'
import Radio from './components/radio'
import Rate from './components/rate'
import Slider from './components/slider'
import Spin from './components/spin'
import Steps from './components/steps'
import Switchs from './components/switch'
import Table from './components/table'
import Tabs from './components/tabs'
import Tag from './components/tag'
import Timeline from './components/timeline'
import TimePicker from './components/time-picker'
import Tooltip from './components/tooltip'
import Transfer from './components/transfer'
import Tree from './components/tree'
import Upload from './components/upload'
import { Row, Col } from './components/grid'
import { Select, Option, OptionGroup } from './components/select'
import locale from './locale'


const BreadcrumbItem = Breadcrumb.Item
const iButton = Button
const ButtonGroup = Button.Group
const CarouselItem = Carousel.Item
const CheckboxGroup = Checkbox.Group
const iCircle = Circles
const DropdownItem = Dropdown.Item
const DropdownMenu = Dropdown.Menu
const iForm = Form
const FormItem = Form.Item
const iCol = Col
const iInput = Input
const iMenu = Menu
const MenuGroup = Menu.Group
const MenuItem = Menu.Item
const Submenu = Menu.Sub
const iOption = Option
const Panel = Collapse.Panel
const iProgress = Progress
const RadioGroup = Radio.Group
const iSelect = Select
const Step = Steps.Step
const iSwitch = Switchs
const iTable = Table
const TabPane = Tabs.Pane
const TimelineItem = Timeline.Item

const iview = {
    Affix,
    Alert,
    BackTop,
    Badge,
    Breadcrumb,
    BreadcrumbItem: Breadcrumb.Item,
    iButton: Button,
    Button,
    ButtonGroup: Button.Group,
    Card,
    Carousel,
    CarouselItem: Carousel.Item,
    Cascader,
    Checkbox,
    CheckboxGroup: Checkbox.Group,
    iCircle: Circles,
    DatePicker,
    Dropdown,
    DropdownItem: Dropdown.Item,
    DropdownMenu: Dropdown.Menu,
    Form,
    iForm: Form,
    FormItem: Form.Item,
    Col,
    iCol: Col,
    Collapse,
    Icon,
    Input,
    iInput: Input,
    InputNumber,
    LoadingBar,
    Menu,
    iMenu: Menu,
    MenuGroup: Menu.Group,
    MenuItem: Menu.Item,
    Submenu: Menu.Sub,
    Message,
    Modal,
    Notice,
    Option: Option,
    iOption: Option,
    OptionGroup,
    Page,
    Panel: Collapse.Panel,
    Poptip,
    Progress,
    iProgress: Progress,
    Radio,
    RadioGroup: Radio.Group,
    Rate,
    Row,
    Select,
    iSelect: Select,
    Slider,
    Spin,
    Step: Steps.Step,
    Steps,
    // Switch,
    iSwitch: Switchs,
    iTable: Table,
    Table,
    Tabs: Tabs,
    TabPane: Tabs.Pane,
    Tag,
    Timeline,
    TimelineItem: Timeline.Item,
    TimePicker,
    Tooltip,
    Transfer,
    Tree,
    Upload
}

const install = function (Vue, opts = {}) {
    locale.use(opts.locale)
    locale.i18n(opts.i18n)

    Object.keys(iview).forEach((key) => {
        Vue.component(key, iview[key])
    })

    Vue.prototype.$Loading = Vue.prototype.$loading = LoadingBar
    Vue.prototype.$Message = Vue.prototype.$message = Message
    Vue.prototype.$Modal = Vue.prototype.$modal = Modal
    Vue.prototype.$Notice = Vue.prototype.$notice = Notice
}

iview.install = install

export {
    Affix,
    Alert,
    BackTop,
    Badge,
    Breadcrumb,
    BreadcrumbItem,
    iButton,
    Button,
    ButtonGroup,
    Card,
    Carousel,
    CarouselItem,
    Cascader,
    Checkbox,
    CheckboxGroup,
    iCircle,
    DatePicker,
    Dropdown,
    DropdownItem,
    DropdownMenu,
    Form,
    iForm,
    FormItem,
    Col,
    iCol,
    Collapse,
    ColorPicker,
    Icon,
    Input,
    iInput,
    InputNumber,
    LoadingBar,
    Menu,
    iMenu,
    MenuGroup,
    MenuItem,
    Submenu,
    Message,
    Modal,
    Notice,
    Option,
    iOption,
    OptionGroup,
    Page,
    Panel,
    Poptip,
    Progress,
    iProgress,
    Radio,
    RadioGroup,
    Rate,
    Row,
    Select,
    iSelect,
    Slider,
    Spin,
    Step,
    Steps,
    // Switch,
    iSwitch,
    iTable,
    Table,
    Tabs,
    TabPane,
    Tag,
    Timeline,
    TimelineItem,
    TimePicker,
    Tooltip,
    Transfer,
    Tree,
    Upload
}

// auto install
if (typeof window !== 'undefined' && window.Vue) {
    install(window.Vue)
}

export default iview

// module.exports = Object.assign(iview, {install})   // eslint-disable-line no-undef
